/**   
 * Copyright © 2016 公司名. All rights reserved.
 * 
 * @Title: CleanOrder.java 
 * @Prject: LianniuWeb
 * @Package: com.lianniu.web.buyerOrder.job
 * @Description: TODO
 * @author: Administrator   
 * @date: 2016年9月12日 下午1:00:15 
 * @version: V1.0   
 */
package com.lianniu.web.buyerOrder.job;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.lianniu.web.buyerOrder.dao.IBuyerOrderDao;
import com.lianniu.web.buyerOrder.model.OrderDetailVo;
import com.lianniu.web.buyerOrder.model.OrderInfoVo;
import com.lianniu.web.product.dao.ISkuProductDao;
import com.lianniu.web.product.model.SkuProductVo;

/** 
 * @ClassName: CleanOrder 
 * @Description: 定时检查超时订单
 * @author: Administrator
 * @date: 2016年9月12日 下午1:00:15  
 */
public class CleanOrderJob {
    @Autowired
    IBuyerOrderDao buyerOrderDao;
    @Autowired
    ISkuProductDao skuProductDao;
    @Transactional
    public void delOrder(){
       List<OrderInfoVo> orderInfoVos = buyerOrderDao.getOutTimeOrders();
       List<OrderDetailVo> ods = new ArrayList<>();
       for(int i =0;i<orderInfoVos.size();i++){
           ods.addAll(orderInfoVos.get(i).getLstOrderDetail());
       }
       List<SkuProductVo> sks = new ArrayList<>();
       for(int i = 0;i<ods.size();i++){
           SkuProductVo sp = new SkuProductVo();
           sp.setId(ods.get(i).getSupplyProductID());
           sp.setOverPlusNum(Double.parseDouble(ods.get(i).getProductNum()));
           sks.add(sp);
       }
       if(null != orderInfoVos && orderInfoVos.size()>0){
           buyerOrderDao.delOutTimeOrder(orderInfoVos);
       }
       if(ods.size()>0){
           buyerOrderDao.delOutTimeOrderDetail(ods); 
       }
       if(sks.size()>0){
           skuProductDao.addOverPlusNum(sks);
       }
    }

}
